class Storage {
  storage: globalThis.Storage;
  constructor(storage: globalThis.Storage = localStorage) {
    this.storage = storage;
  }
  setItem(key: string, value: any) {
    if (typeof value === "undefined") return;
    if (typeof value === "string") {
      this.storage.setItem(key, value);
      return;
    }
    this.storage.setItem(key, JSON.stringify(value));
  }

  getItem(key: string) {
    try {
      return JSON.parse(localStorage.getItem(key) || "");
    } catch {
      return localStorage.getItem(key);
    }
  }

  removeItem(key: string) {
    this.storage.removeItem(key);
  }
}

export const ll = new Storage();
export const ss = new Storage(sessionStorage);
